<?php
class userIdentity extends dpUserIdentity
{
	public function authenticate()
	{
		if(empty($this->username) || empty($this->password))
		{
			$this->errorMsg = '用户名和密码不能为空';
			return false;
		}
		$user = userModel::model()->findByAttribute(
			array('uid','gid','username','password'),
			'username=:username',
			array(':username'=>$this->username)
		);

		if(empty($user))
		{	
			$this->errorMsg = '用户不存在';
			return false; 
		}
		if(!$this->_matchPwd($this->password, $user['password']))
		{	
			$this->errorMsg = '密码不正确';
			return false;
		}

		$this->uid = $user['uid'];
		$this->gid = $user['gid'];
		return true;	
	}

	private function _matchPwd($password, $inputPwd)
	{
		return md5(md5($password.'_dp')) === $inputPwd ? true : false;
	}
}

?>